﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;


namespace Portal
{

    /// <summary>
    /// 缓存重置特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Interface, AllowMultiple = false)]
    public class CacheResetFilterAttribute : ActionFilterAttribute
    {
        public string[] Key { get; set; }
        public Action<string, bool> RestSet { get; set; }


        public CacheResetFilterAttribute()
        {

        }
        public CacheResetFilterAttribute(params string[] key)
        {
            Key = key;
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {

        }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            foreach (var item in Key)
            {
                if (!string.IsNullOrEmpty(item.NullSafe().Trim()))
                    Cache.Remove(item);
            }
        }



    }

}
